All Questions
Tagged with programming-practicesclean-code
31 questions
-3votes
2answers
700views
Is throwing an error in programming is good Idea at all? [duplicate]
I am wondering if throwing an error in programming is good Idea at all ? While programming we throw error when something unexpected or invalid has occurred. But if we have thrown exception and it is ...
9votes
2answers
1kviews
Should function names describe their parameter types?
If you wish to perform the same action using different parameters, you can either make differently named functions: public Apple findAppleById(long id){ return repo.findById(id); } public Apple ...
1vote
1answer
139views
What is the best approach to use a common variable in multiple method in a request in laravel [closed]
I have a $c variable that is calculated at the beginning of the request. After calculating this several nested methods use it as a part of their job. Is it better that I pass down the $c variable to ...
20votes
8answers
22kviews
Is an empty 'while' loop bad practice?
Consider the following: public boolean maybeUpdateTime() { if (this.timeReference.isAfter(lastInterval.getBeginning()) { this.timeReference = lastInterval.getEnd(); lastInterval = ...
-1votes
1answer
195views
Angular: send form or object?
My question is about clean code or best practice. I have a big formGroup and in my opinion its more difficult to map the form to an object than to send the form to the backend. best regards
1vote
1answer
206views
counting identifiers and operators as code size metric
I'm looking for a code metric for monitor and track over time the size of several projects and their components. Also, I would like to use it for: evaluate size reduction after refactoring compare ...
0votes
1answer
166views
Visibility of constants
Should constants of my class only be public if I know that they will be used from their users or doesn't it hurt to make all of my constants public per se? Is not exposing all constants cleaner?
12votes
6answers
4kviews
Passing Objects vs. Primitives
What is the best practice when it comes to passing variables around? Is it better to pass objects (models) or is it better to pass primitives that will be required by the called method? What are the ...
138votes
17answers
15kviews
How do I know how reusable my methods should be? [closed]
I am minding my own business at home and my wife comes to me and says Honey.. Can you print all the Day Light Savings around the world for 2018 in the console? I need to check something. And I am ...
0votes
3answers
541views
Bug-preventing vs clean code
If I'm faced with the decision to write clean, beautiful code, but I'd be opening up a new path bugs could take to appear, should I take it? (Provided I'm not willing to spend the time to come up with ...
0votes
4answers
460views
Best practice to populate a `container` class
lets say I have several objects Object A,Object B,Object C in different parts of my project. I have defined a Object X that is only used to store some specific values from the objects mentioned above ...
4votes
6answers
1kviews
How to deal with Law of Demeter in the product - owner relationship?
I want to display the product, and the product card has a lot of information about the product and the owner. How to deal with Law of Demeter in this product - owner relationship? In controller I ...
8votes
6answers
5kviews
What is more important? SOLID or KISS?
What is more important? SOLID or KISS? To be consistent with SOLID I would have to inject Decorator and Footer classes and create interfaces for them. public class HelloService { String name; ...
7votes
5answers
8kviews
What to do with long variable names?
First example: countryRepository.getCountriesFromAsiaWhereAreTheMostPlanesAndBoats(); countryRepository.getCountriesFromAfricaWhereAreTheMostCars(); Are these names too big? How else do we call these ...
-3votes
3answers
491views
Writing quality code [closed]
I know there are many books on writing clean, modular, readable and whatever else you can say but frankly speaking I find it very hard to remember every advice given on those books. Frankly speaking ...